<?php

use swap\service_except;
use swap\visitor;

class user_limit_service extends swap\service {

    public static function excess_resume() {
        $user_id = visitor::get_role_id('user');
        $user_limit = user_limit_model::get_one(array('user_id' => $user_id));
        return user_limit_model::resume - $user_limit->resume_count;
    }
    
    public static function check_resume_count($resume_count) {
        if (self::is_user_limited($resume_count, user_limit_model::resume)) {
            service_except::throw_prop_msg('resume', '您的简历已经有5份了');
        }
    }
    public static function check_letter_count($letter_count) {
        if (self::is_user_limited($letter_count, user_limit_model::letter)) {
            service_except::throw_prop_msg('resume', '您的求职信已经有5份了');
        }
    }
    
    protected static function is_user_limited($user_limit, $system_limit) {
        return $user_limit >= $system_limit;
    }

}